package base.thread.state.join;

/**
 * @Author: my_code
 * @Create: 2020-12-08 13:57
 *
 * join合并线程，待此线程执行完成后，再执行其他的线程，其他线程阻塞
 * 可以想象从插队
 */
public class JoinTest implements Runnable {

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName());
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        JoinTest joinTest = new JoinTest();
        Thread thread = new Thread(joinTest,"joinTest");
        thread.start();
        for (int i = 0; i < 10; i++) {
            if (i == 5) {
                thread.join();
            }
            System.out.println("main:" + i);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
}
